home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
util
/
pack
/
xpk_Develop.lha
/
xpk_Develop
/
Include
/
C
/
xpk
/
xpkLibHeader.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-18
|
6KB
|
195 lines
/*************** $VER: xpkLibHeader.c 1.3 (18.12.1998) ******************/
#include <exec/initializers.h>
#include <exec/resident.h>
#include <proto/exec.h>
#include "SDI_compiler.h"
struct LibInitData {
UBYTE i_Type; UBYTE o_Type; UBYTE d_Type; UBYTE p_Type;
UBYTE i_Name; UBYTE o_Name; STRPTR d_Name;
UBYTE i_Flags; UBYTE o_Flags; UBYTE d_Flags; UBYTE p_Flags;
UBYTE i_Version; UBYTE o_Version; UWORD d_Version;
UBYTE i_Revision; UBYTE o_Revision; UWORD d_Revision;
UBYTE i_IdString; UBYTE o_IdString; STRPTR d_IdString;
ULONG endmark;
};
/************************************************************************/
LONG ReturnError(void);
LONG LibReserved(void);
ASM(BPTR) LibExpunge(REG(a6, struct XpkSubBase *));
ASM(BPTR) LibClose(REG(a6, struct XpkSubBase *));
ASM(struct XpkSubBase *) LibOpen(REG(a6, struct XpkSubBase *));
ASM(struct XpkSubBase *) LibInit(REG(a0, BPTR), REG(d0, struct XpkSubBase *),
REG(a6, struct ExecBase *));
/************************************************************************/
ASM(struct XpkInfo *) LIBXpksPackerInfo(void);
ASM(LONG) LIBXpksPackChunk(REG(a0,struct XpkSubParams *),
REG(a6, struct XpkSubBase *));
ASM(void) LIBXpksPackFree(REG(a0,struct XpkSubParams *),
REG(a6, struct xpkSubBase *));
ASM(LONG) LIBXpksPackReset(REG(a0,struct XpkSubParams *),
REG(a6, struct XpkSubBase *));
ASM(LONG) LIBXpksUnpackChunk(REG(a0,struct XpkSubParams *),
REG(a6, struct XpkSubBase *));
ASM(void) LIBXpksUnpackFree(REG(a0,struct XpkSubParams *),
REG(a6, struct xpkSubBase *));
/************************************************************************/
/* First executable routine of this library; must return an error
to the unsuspecting caller */
LONG ReturnError(void)
{
return -1;
}
/* The mandatory reserved library function */
LONG LibReserved(void)
{
return 0;
}
/* Expunge the library, remove it from memory */
ASM(BPTR) LibExpunge(REG(a6, struct XpkSubBase *XpkSubBase))
{
BPTR Result = 0;
/* Expunge it later */
XpkSubBase->xsb_LibNode.lib_Flags |= LIBF_DELEXP;
/* Can we get away with this? */
if(!XpkSubBase->xsb_LibNode.lib_OpenCnt)
{
struct ExecBase *SysBase = XpkSubBase->xsb_SysBase;
xExitCode(XpkSubBase);
/* Remove the library from the public list */
Remove((struct Node *)XpkSubBase);
/* Return the seglist, so it can be unloaded */
Result = XpkSubBase->xsb_SegList;
/* Free the vector table and the library data */
FreeMem((STRPTR) XpkSubBase-XpkSubBase->xsb_LibNode.lib_NegSize,
XpkSubBase->xsb_LibNode.lib_NegSize+XpkSubBase->xsb_LibNode.lib_PosSize);
}
/* Return the segment pointer, if any */
return Result;
}
/* Close the library, as called by CloseLibrary() */
ASM(BPTR) LibClose(REG(a6, struct XpkSubBase *XpkSubBase))
{
BPTR Result = 0;
if(!(--XpkSubBase->xsb_LibNode.lib_OpenCnt))
{
if(XpkSubBase->xsb_LibNode.lib_Flags & LIBF_DELEXP)
Result = LibExpunge(XpkSubBase);
}
return Result;
}
/* Open the library, as called via OpenLibrary() */
ASM(struct XpkSubBase *) LibOpen(REG(a6, struct XpkSubBase *XpkSubBase))
{
/* Prevent delayed expunge and increment opencnt */
XpkSubBase->xsb_LibNode.lib_Flags &= ~LIBF_DELEXP;
XpkSubBase->xsb_LibNode.lib_OpenCnt++;
/* return base */
return XpkSubBase;
}
/* Initialize the library */
ASM(struct XpkSubBase *) LibInit(REG(a0, BPTR SegList),
REG(d0, struct XpkSubBase *XpkSubBase), REG(a6, struct ExecBase *SysBase))
{
/* Remember the segment pointer */
XpkSubBase->xsb_SegList = SegList;
/* Remember the exec library base pointer */
XpkSubBase->xsb_SysBase = SysBase;
if(xInitCode(XpkSubBase))
{
xExitCode(XpkSubBase);
/* Free the vector table and the library data */
FreeMem((STRPTR) XpkSubBase-XpkSubBase->xsb_LibNode.lib_NegSize,
XpkSubBase->xsb_LibNode.lib_NegSize+XpkSubBase->xsb_LibNode.lib_PosSize);
XpkSubBase = 0;
}
return XpkSubBase;
}
/************************************************************************/
/* This is the table of functions that make up the library. The first
four are mandatory, everything following it are user callable
routines. The table is terminated by the value -1. */
static const APTR LibVectors[20] = {
(APTR)LibOpen,
(APTR)LibClose,
(APTR)LibExpunge,
(APTR)LibReserved,
(APTR)LIBXpksPackerInfo,
(APTR)LIBXpksPackChunk,
(APTR)LIBXpksPackFree,
(APTR)LIBXpksPackReset,
(APTR)LIBXpksUnpackChunk,
(APTR)LIBXpksUnpackFree,
(APTR)-1
};
static const struct LibInitData LibInitData = {
0xA0, (UBYTE) OFFSET(Node, ln_Type), NT_LIBRARY, 0,
0x80, (UBYTE) OFFSET(Node, ln_Name), LIBNAME,
0xA0, (UBYTE) OFFSET(Library, lib_Flags), LIBF_SUMUSED|LIBF_CHANGED, 0,
0x90, (UBYTE) OFFSET(Library, lib_Version), VERSION,
0x90, (UBYTE) OFFSET(Library, lib_Revision), REVISION,
0x80, (UBYTE) OFFSET(Library, lib_IdString), IDSTRING,
0
};
/* The following data structures and data are responsible for
setting up the Library base data structure and the library
function vector. */
static const ULONG LibInitTable[4] = {
(ULONG)sizeof(struct XpkSubBase), /* Size of the base data structure */
(ULONG)LibVectors, /* Points to the function vector */
(ULONG)&LibInitData, /* Library base data structure setup table */
(ULONG)LibInit /* The address of the routine to do the setup */
};
/************************************************************************/
/* The library loader looks for this marker in the memory
the library code and data will occupy. It is responsible
setting up the Library base data structure.
*/
static const struct Resident RomTag = {
RTC_MATCHWORD, /* Marker value. */
(struct Resident *)&RomTag, /* This points back to itself. */
(struct Resident *)&RomTag+1, /* This points behind this marker. */
RTF_AUTOINIT, /* The Library should be set up according to the given table. */
VERSION, /* The version of this Library. */
NT_LIBRARY, /* This defines this module as a Library. */
0, /* Initialization priority of this Library; unused. */
LIBNAME, /* Points to the name of the Library. */
IDSTRING, /* The identification string of this Library. */
(APTR)&LibInitTable /* This table is for initializing the Library. */
};